package com.kevin.demo.util;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.HashMap;
import java.util.Map;

/**
 * 配置文件加载类
 * 
 * @author kevin
 */
public class PropertiesLoaderUtil {

	public static Map<String, Object> load(String pathname) throws IOException {
		// 读取配置文件
		File file = new File(pathname);
		if (!file.exists()) {
			System.out.println("文件不存在");
			return null;
		}
		
		Map<String, Object> result = new HashMap<String, Object>();
		InputStream fis = new FileInputStream(file);
		InputStreamReader isr = new InputStreamReader(fis, "UTF-8");
		BufferedReader reader = new BufferedReader(isr);
		// 读取字符流数据
		String lineStr = null;
		while ((lineStr = reader.readLine()) != null) {
			System.out.println(lineStr);
			String[] strs = lineStr.split("=");
			// 第一个是key，第二个是value
			String key = strs[0];
			String value = strs[1];
			result.put(key, value);
		}
		reader.close();
		return result;
	}

}
